package com.example.demo.controller;

import com.example.demo.dao.model.SysSession;
import com.example.demo.dao.model.SysToken;
import com.example.demo.service.ISessionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("session")
public class SessionController {

    private static final Logger logger = LoggerFactory.getLogger(SessionController.class);

    @Autowired
    @Qualifier("jimmy_sessionService")
    private ISessionService sessionService;

    @GetMapping("/{id}")
    public SysSession getSession(@PathVariable("id") String id) {

        return this.sessionService.selectOne(id);
    }

    @GetMapping("/list")
    public List<SysSession> getSessions(String sessionId) throws Exception {
        logger.debug("Get session list api invoked.");
        logger.info("Get...");
        logger.error("");
        return this.sessionService.selectMany(null);
    }


    @PostMapping("/new")
    public Boolean newSession(@RequestBody SysSession session) {
        return this.sessionService.insertSession(session);
    }

    @PutMapping("/edit")
    public Boolean updateSession(@RequestBody SysSession session) {
        return this.sessionService.updateSession(session);
    }
}
